﻿cmake_minimum_required(VERSION 3.3)
project("mtp_2_0")

SET(CMAKE_BUILD_TYPE Release)
add_compile_options(-fPIC)
if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "ppc64le")
  #powerlinux ppc64le not support link gcc  static library
  SET(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -fPIC -O2 -g -ggdb -Wall -m64 -std=c++11 -lrt -lpthread -latomic")
  SET(CMAKE_CXX_COMPILER "g++")
else()
  #for x86 and powerlinux ppc64
  SET(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -fPIC -O2 -g -ggdb -Wall -m64 -std=c++11 -lrt -static-libgcc -static-libstdc++")
  SET(CMAKE_CXX_COMPILER "/usr/local/bin/g++")
endif()


function(use_library_type)
  string(TOLOWER ${ARGV0} type)
  if (${type} STREQUAL "shared")
    set(LIBRARY_NAME_SUFFIX ".so" PARENT_SCOPE)
  else()
    set(LIBRARY_NAME_SUFFIX ".a" PARENT_SCOPE)
  endif()
endfunction()

#build depends
option(OPT_BUILD_DEPENDS "build depend library" ON)

function(add_depends)
  unset(curr_project_library PARENT_SCOPE)

  foreach(trd ${ARGN})
    string(TOLOWER ${trd} dist)
    message(STATUS "add ${dist} head and library file")
    
    if (${dist} STREQUAL "busdriver")
      INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/2nd/driver/include)
      INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/2nd/driver/include/busdriver)
      LINK_DIRECTORIES(${PROJECT_SOURCE_DIR}/2nd/driver/lib/${CMAKE_SYSTEM_NAME}_${CMAKE_SYSTEM_PROCESSOR})
      if (OPT_BUILD_DEPENDS)
        if (NOT TARGET ${dist})
            ADD_SUBDIRECTORY(${PROJECT_SOURCE_DIR}/2nd/driver ${CMAKE_BINARY_DIR}/${dist} EXCLUDE_FROM_ALL)
        endif()
        list(APPEND curr_project_library ${dist})
      else()
        list(APPEND curr_project_library lib${dist}${LIBRARY_NAME_SUFFIX})
      endif()
    endif()

    if (${dist} STREQUAL "protobuf")
      INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rd/protobuf-2.5.0/src)
      LINK_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rd/protobuf-2.5.0/lib/${CMAKE_SYSTEM_NAME}_${CMAKE_SYSTEM_PROCESSOR})
      list(APPEND curr_project_library libprotobuf${LIBRARY_NAME_SUFFIX})
    endif()

    if (${dist} STREQUAL "protobuf-so")
      INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rd/protobuf-2.5.0/src)
      LINK_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rd/protobuf-2.5.0/lib/${CMAKE_SYSTEM_NAME}_${CMAKE_SYSTEM_PROCESSOR})
      list(APPEND curr_project_library libprotobuf.so)
    endif()

    if (${dist} STREQUAL "protobuf3.5")
      INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rd/protobuf-3.5.0/src)
      LINK_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rd/protobuf-3.5.0/lib/${CMAKE_SYSTEM_NAME}_${CMAKE_SYSTEM_PROCESSOR})
      list(APPEND curr_project_library libprotobuf${LIBRARY_NAME_SUFFIX})
    endif()

    if (${dist} STREQUAL "proto")
      INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/protocol/)
      INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/protocol/src)
      INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/protocol/src/generated_pb/source)
      LINK_DIRECTORIES(${PROJECT_SOURCE_DIR}/protocol/lib/${CMAKE_SYSTEM_NAME}_${CMAKE_SYSTEM_PROCESSOR})
      if (OPT_BUILD_DEPENDS)
        if (NOT TARGET ${dist})
            ADD_SUBDIRECTORY(${PROJECT_SOURCE_DIR}/protocol ${CMAKE_BINARY_DIR}/${dist} EXCLUDE_FROM_ALL)
        endif()
        list(APPEND curr_project_library ${dist})
      else()
        list(APPEND curr_project_library lib${dist}${LIBRARY_NAME_SUFFIX})
      endif()
    endif()

    if (${dist} STREQUAL "curl")
      INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rd/curl-7.49.1/include)
      LINK_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rd/curl-7.49.1/lib/${CMAKE_SYSTEM_NAME}_${CMAKE_SYSTEM_PROCESSOR})
      list(APPEND curr_project_library libcurl${LIBRARY_NAME_SUFFIX})
    endif()
    
    if (${dist} STREQUAL "libevent")
      INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rd/libevent-2.0.22-stable/include)
      LINK_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rd/libevent-2.0.22-stable/lib/${CMAKE_SYSTEM_NAME}_${CMAKE_SYSTEM_PROCESSOR})
      list(APPEND curr_project_library libevent${LIBRARY_NAME_SUFFIX})
    endif()

    if (${dist} STREQUAL "zlib")
      INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rd/zlib-1.2.8)
      LINK_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rd/zlib-1.2.8/lib/${CMAKE_SYSTEM_NAME}_${CMAKE_SYSTEM_PROCESSOR})
      list(APPEND curr_project_library libz${LIBRARY_NAME_SUFFIX})
    endif()

    if (${dist} STREQUAL "loki")
      INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rd/loki-0.1.7/include)
      LINK_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rd/loki-0.1.7/lib/${CMAKE_SYSTEM_NAME}_${CMAKE_SYSTEM_PROCESSOR})
      list(APPEND curr_project_library libloki${LIBRARY_NAME_SUFFIX})
    endif()

    if (${dist} STREQUAL "log4cplus")
      INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rd/log4cplus-REL_1_2_0-RC5/include)
      LINK_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rd/log4cplus-REL_1_2_0-RC5/lib/${CMAKE_SYSTEM_NAME}_${CMAKE_SYSTEM_PROCESSOR})
      list(APPEND curr_project_library liblog4cplus.so)
    endif()

    if (${dist} STREQUAL "monitoragent")
      INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/2nd/monitor/include)
    endif()

    if (${dist} STREQUAL "sm_agent")
      INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/2nd/util/include/Sm_Agent)
      LINK_DIRECTORIES(${PROJECT_SOURCE_DIR}/2nd/sm_agent/lib/${CMAKE_SYSTEM_NAME}_${CMAKE_SYSTEM_PROCESSOR})
      list(APPEND curr_project_library lib_sm_agent${LIBRARY_NAME_SUFFIX})
    endif()

    
    if (${dist} STREQUAL "xerces")
      INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rd/xerces-c-3.1.2/include/${CMAKE_SYSTEM_NAME}_${CMAKE_SYSTEM_PROCESSOR})    
      LINK_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rd/xerces-c-3.1.2/lib/${CMAKE_SYSTEM_NAME}_${CMAKE_SYSTEM_PROCESSOR})
      #add xerces library
      list(APPEND curr_project_library libxerces-c${LIBRARY_NAME_SUFFIX})
    endif()

    if (${dist} STREQUAL "xsd")
      INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rd/xsd-4.0.0/include)
    endif()

    if (${dist} STREQUAL "openssl")
      INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rd/openssl-OpenSSL_1_0_2-stable/include/${CMAKE_SYSTEM_NAME}_${CMAKE_SYSTEM_PROCESSOR})    
      LINK_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rd/openssl-OpenSSL_1_0_2-stable/lib/${CMAKE_SYSTEM_NAME}_${CMAKE_SYSTEM_PROCESSOR})
      list(APPEND curr_project_library libssl${LIBRARY_NAME_SUFFIX})
      list(APPEND curr_project_library libcrypto${LIBRARY_NAME_SUFFIX})
    endif()

    if (${dist} STREQUAL "hiredis")
      INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rd/hiredis/include/${CMAKE_SYSTEM_NAME}_${CMAKE_SYSTEM_PROCESSOR})    
      LINK_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rd/hiredis/lib/${CMAKE_SYSTEM_NAME}_${CMAKE_SYSTEM_PROCESSOR})
      #add xerces library
      list(APPEND curr_project_library libhiredis.so)
    endif()

    if (${dist} STREQUAL "muchinfodb")
      INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/2nd/db/include)
      LINK_DIRECTORIES(${PROJECT_SOURCE_DIR}/2nd/db/lib/${CMAKE_SYSTEM_NAME}_${CMAKE_SYSTEM_PROCESSOR})    
      if (OPT_BUILD_DEPENDS)
        if (NOT TARGET ${dist})
            ADD_SUBDIRECTORY(${PROJECT_SOURCE_DIR}/2nd/db ${CMAKE_BINARY_DIR}/${dist} EXCLUDE_FROM_ALL)
        endif()
        list(APPEND curr_project_library ${dist})
      else()
        list(APPEND curr_project_library lib${dist}${LIBRARY_NAME_SUFFIX})
      endif()
    endif()

    if (${dist} STREQUAL "muchinfolog")
      INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/2nd/loggers/include)
      LINK_DIRECTORIES(${PROJECT_SOURCE_DIR}/2nd/loggers/lib/${CMAKE_SYSTEM_NAME}_${CMAKE_SYSTEM_PROCESSOR})
      if (OPT_BUILD_DEPENDS)
        if (NOT TARGET ${dist})
            ADD_SUBDIRECTORY(${PROJECT_SOURCE_DIR}/2nd/loggers ${CMAKE_BINARY_DIR}/${dist} EXCLUDE_FROM_ALL)
        endif()
        list(APPEND curr_project_library ${dist})
      else()
        list(APPEND curr_project_library lib${dist}${LIBRARY_NAME_SUFFIX})
      endif()
    endif()

    if (${dist} STREQUAL "marketgoodsstatus")
      INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/2nd/marketgoodsstatus/include)
      LINK_DIRECTORIES(${PROJECT_SOURCE_DIR}/2nd/marketgoodsstatus/lib/${CMAKE_SYSTEM_NAME}_${CMAKE_SYSTEM_PROCESSOR})
      if (OPT_BUILD_DEPENDS)
        if (NOT TARGET ${dist})
            ADD_SUBDIRECTORY(${PROJECT_SOURCE_DIR}/2nd/marketgoodsstatus ${CMAKE_BINARY_DIR}/${dist} EXCLUDE_FROM_ALL)
        endif()
        list(APPEND curr_project_library ${dist})
      else()
        list(APPEND curr_project_library lib${dist}${LIBRARY_NAME_SUFFIX})
      endif()
    endif()

    if (${dist} STREQUAL "muchinfocfg")
      INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/2nd/config/include)
      LINK_DIRECTORIES(${PROJECT_SOURCE_DIR}/2nd/config/lib/${CMAKE_SYSTEM_NAME}_${CMAKE_SYSTEM_PROCESSOR})
      list(APPEND curr_project_library libmuchinfocfg${LIBRARY_NAME_SUFFIX})
    endif()

    if (${dist} STREQUAL "redisclient")
      INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/2nd/redis_client/include)
      LINK_DIRECTORIES(${PROJECT_SOURCE_DIR}/2nd/redis_client/lib/${CMAKE_SYSTEM_NAME}_${CMAKE_SYSTEM_PROCESSOR})
      if (OPT_BUILD_DEPENDS)
        if (NOT TARGET ${dist})
            ADD_SUBDIRECTORY(${PROJECT_SOURCE_DIR}/2nd/redis_client ${CMAKE_BINARY_DIR}/${dist} EXCLUDE_FROM_ALL)
        endif()
        list(APPEND curr_project_library ${dist})
      else()
        list(APPEND curr_project_library lib${dist}${LIBRARY_NAME_SUFFIX})
      endif()
    endif()

    if (${dist} STREQUAL "idgenerator")
      INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/2nd/idgenerator/include)
      LINK_DIRECTORIES(${PROJECT_SOURCE_DIR}/2nd/idgenerator/lib/${CMAKE_SYSTEM_NAME}_${CMAKE_SYSTEM_PROCESSOR})
      if (OPT_BUILD_DEPENDS)
        if (NOT TARGET ${dist})
            ADD_SUBDIRECTORY(${PROJECT_SOURCE_DIR}/2nd/idgenerator ${CMAKE_BINARY_DIR}/${dist} EXCLUDE_FROM_ALL)
        endif()
        list(APPEND curr_project_library ${dist})
      else()
        list(APPEND curr_project_library lib${dist}${LIBRARY_NAME_SUFFIX})
      endif()
    endif()

    if (${dist} STREQUAL "marketgoodsstatus")
      INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/2nd/marketgoodsstatus/include)
      LINK_DIRECTORIES(${PROJECT_SOURCE_DIR}/2nd/marketgoodsstatus/lib/${CMAKE_SYSTEM_NAME}_${CMAKE_SYSTEM_PROCESSOR})
      if (OPT_BUILD_DEPENDS)
        if (NOT TARGET ${dist})
            ADD_SUBDIRECTORY(${PROJECT_SOURCE_DIR}/2nd/marketgoodsstatus ${CMAKE_BINARY_DIR}/${dist} EXCLUDE_FROM_ALL)
        endif()
        list(APPEND curr_project_library ${dist})
      else()
        list(APPEND curr_project_library lib${dist}${LIBRARY_NAME_SUFFIX})
      endif()
    endif()

    if (${dist} STREQUAL "crypto")
      INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/2nd/crypto/include)
      LINK_DIRECTORIES(${PROJECT_SOURCE_DIR}/2nd/crypto/lib/${CMAKE_SYSTEM_NAME}_${CMAKE_SYSTEM_PROCESSOR})
      set(dist "mism")
      if (OPT_BUILD_DEPENDS)
        if (NOT TARGET ${dist})
            ADD_SUBDIRECTORY(${PROJECT_SOURCE_DIR}/2nd/crypto ${CMAKE_BINARY_DIR}/${dist} EXCLUDE_FROM_ALL)
        endif()
        list(APPEND curr_project_library ${dist})
      else()
        list(APPEND curr_project_library lib${dist}${LIBRARY_NAME_SUFFIX})
      endif()
      #add openssl crypto library
      LINK_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rd/openssl-OpenSSL_1_0_2-stable/lib/${CMAKE_SYSTEM_NAME}_${CMAKE_SYSTEM_PROCESSOR})
      list(APPEND curr_project_library libcrypto${LIBRARY_NAME_SUFFIX})
    endif()

    if (${dist} STREQUAL "envparam")
      INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/2nd/envparam/include)
      LINK_DIRECTORIES(${PROJECT_SOURCE_DIR}/2nd/envparam/lib/${CMAKE_SYSTEM_NAME}_${CMAKE_SYSTEM_PROCESSOR})
      if (OPT_BUILD_DEPENDS)
        if (NOT TARGET ${dist})
            ADD_SUBDIRECTORY(${PROJECT_SOURCE_DIR}/2nd/envparam ${CMAKE_BINARY_DIR}/${dist} EXCLUDE_FROM_ALL)
        endif()
        list(APPEND curr_project_library ${dist})
      else()
        list(APPEND curr_project_library lib${dist}${LIBRARY_NAME_SUFFIX})
      endif()
    endif()

    if (${dist} STREQUAL "sqlapi")
      INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rd/sqlapi-4.1.2/include)
      INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rd/sqlapi-4.1.2/include/ora_linux)
      LINK_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rd/sqlapi-4.1.2/lib/${CMAKE_SYSTEM_NAME}_${CMAKE_SYSTEM_PROCESSOR})
      list(APPEND curr_project_library libsqlapi${LIBRARY_NAME_SUFFIX})
    endif()

    if (${dist} STREQUAL "pugixml")
      INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rd/pugixml-1.4/src)
      LINK_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rd/pugixml-1.4/lib/${CMAKE_SYSTEM_NAME}_${CMAKE_SYSTEM_PROCESSOR})
      list(APPEND curr_project_library libpugixml${LIBRARY_NAME_SUFFIX})
    endif()

    if (${dist} STREQUAL "exception")
      INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/2nd/exception/include)
    endif()

    if (${dist} STREQUAL "boost")
      INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rd/boost_1_64_0)
      LINK_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rd/boost_1_64_0/lib/${CMAKE_SYSTEM_NAME}_${CMAKE_SYSTEM_PROCESSOR})
      list(APPEND curr_project_library libboost_system${LIBRARY_NAME_SUFFIX})
      list(APPEND curr_project_library libboost_thread${LIBRARY_NAME_SUFFIX})
      list(APPEND curr_project_library libboost_chrono${LIBRARY_NAME_SUFFIX})
      list(APPEND curr_project_library libboost_regex${LIBRARY_NAME_SUFFIX})
      list(APPEND curr_project_library libboost_date_time${LIBRARY_NAME_SUFFIX})
      list(APPEND curr_project_library libboost_program_options${LIBRARY_NAME_SUFFIX})
      list(APPEND curr_project_library libboost_filesystem${LIBRARY_NAME_SUFFIX})
      list(APPEND curr_project_library libboost_locale${LIBRARY_NAME_SUFFIX})
      list(APPEND curr_project_library libboost_serialization${LIBRARY_NAME_SUFFIX})
    endif()
	
	if (${dist} STREQUAL "boost159")
      INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rd/boost_1_59_0)
      LINK_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rd/boost_1_59_0/lib/${CMAKE_SYSTEM_NAME}_${CMAKE_SYSTEM_PROCESSOR})
      list(APPEND curr_project_library libboost_system${LIBRARY_NAME_SUFFIX})
      list(APPEND curr_project_library libboost_thread${LIBRARY_NAME_SUFFIX})
      list(APPEND curr_project_library libboost_chrono${LIBRARY_NAME_SUFFIX})
      list(APPEND curr_project_library libboost_regex${LIBRARY_NAME_SUFFIX})
      list(APPEND curr_project_library libboost_date_time${LIBRARY_NAME_SUFFIX})
      list(APPEND curr_project_library libboost_program_options${LIBRARY_NAME_SUFFIX})
      list(APPEND curr_project_library libboost_filesystem${LIBRARY_NAME_SUFFIX})
      list(APPEND curr_project_library libboost_locale${LIBRARY_NAME_SUFFIX})
      list(APPEND curr_project_library libboost_serialization${LIBRARY_NAME_SUFFIX})
    endif()

    if (${dist} STREQUAL "taptradeapi9") 
        INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rd/taptradeapi9.0/include)
        LINK_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rd/taptradeapi9.0/lib/${CMAKE_SYSTEM_NAME}_${CMAKE_SYSTEM_PROCESSOR})
        list(APPEND curr_project_library libiTapTradeAPI.so)
    endif()

    if (${dist} STREQUAL "ctptradeapi") 
      INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rd/ctptradeapi6.3.15/include)
      LINK_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rd/ctptradeapi6.3.15/lib/${CMAKE_SYSTEM_NAME}_${CMAKE_SYSTEM_PROCESSOR})
      list(APPEND curr_project_library libthosttraderapi_se.so libLinuxDataCollect.so)
    endif()

    if (${dist} STREQUAL "ctptradeapisim") 
      INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rd/ctptradeapi6.3.6/include)
      LINK_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rd/ctptradeapi6.3.6/lib/${CMAKE_SYSTEM_NAME}_${CMAKE_SYSTEM_PROCESSOR})
      list(APPEND curr_project_library libthosttraderapi.so)
    endif()

    if (${dist} STREQUAL "datradeapi") 
      INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rd/datradeapi-1.11/include)
      LINK_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rd/datradeapi-1.11/lib/${CMAKE_SYSTEM_NAME}_${CMAKE_SYSTEM_PROCESSOR})
      list(APPEND curr_project_library libDAApi.so)
    endif()

    if (${dist} STREQUAL "huobiapi") 
      INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rd/huobiapi-1.0.1/include)
      INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rd/libdecnumber/include/decnumber)
      LINK_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rd/huobiapi-1.0.1/lib/${CMAKE_SYSTEM_NAME}_${CMAKE_SYSTEM_PROCESSOR})
      list(APPEND curr_project_library HuobiClient${LIBRARY_NAME_SUFFIX})
    endif()

    if (${dist} STREQUAL "futuapi") 
      INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rd/futuapi-3.14.0/include)
      LINK_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rd/futuapi-3.14.0/lib/${CMAKE_SYSTEM_NAME}_${CMAKE_SYSTEM_PROCESSOR})
      list(APPEND curr_project_library FTAPI${LIBRARY_NAME_SUFFIX})
      list(APPEND curr_project_library libFTAPIChannel.so)
    endif()

    if (${dist} STREQUAL "cryptopp")
      INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rd/cryptopp-CRYPTOPP_5_6_5)
      LINK_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rd/cryptopp-CRYPTOPP_5_6_5/lib/${CMAKE_SYSTEM_NAME}_${CMAKE_SYSTEM_PROCESSOR})
      list(APPEND curr_project_library cryptopp${LIBRARY_NAME_SUFFIX})
    endif()
    
   if (${dist} STREQUAL "gmock")
      INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rd/googlemock-release-1.7.0/include)
      INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rd/googlemock-release-1.7.0/gtest/include)
      LINK_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rd/googlemock-release-1.7.0/lib/${CMAKE_SYSTEM_NAME}_${CMAKE_SYSTEM_PROCESSOR})
      list(APPEND curr_project_library libgmock${LIBRARY_NAME_SUFFIX})
    endif()

    if (${dist} STREQUAL "libdl")
      list(APPEND curr_project_library libdl.so)
    endif()

    if (${dist} STREQUAL "pthread")
      list(APPEND curr_project_library pthread)
    endif()

    if (${dist} STREQUAL "breakpad")
      INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/2nd/crash_report/include)
      INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rd/breakpad/include/${CMAKE_SYSTEM_NAME}_${CMAKE_SYSTEM_PROCESSOR})
      ADD_DEFINITIONS(-D__STDC_FORMAT_MACROS)
      string(TOLOWER ${CMAKE_SYSTEM_NAME} lower_system_name)
      INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rd/breakpad/include/${CMAKE_SYSTEM_NAME}_${CMAKE_SYSTEM_PROCESSOR}/client/${lower_system_name}/handler)
      LINK_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rd/breakpad/lib/${CMAKE_SYSTEM_NAME}_${CMAKE_SYSTEM_PROCESSOR})
      if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")
        list(APPEND curr_project_library libbreakpad_client${LIBRARY_NAME_SUFFIX})
        list(APPEND curr_project_library libbreakpad${LIBRARY_NAME_SUFFIX})
      endif()
    endif()

    if (${dist} STREQUAL "gperftools")
      LINK_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rd/gperftools-2.5/lib/${CMAKE_SYSTEM_NAME}_${CMAKE_SYSTEM_PROCESSOR})
      list(APPEND curr_project_library libtcmalloc_minimal${LIBRARY_NAME_SUFFIX})
    endif()

    if (${dist} STREQUAL "sasl")
      LINK_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rd/cyrus-sasl-2.1.27/lib/${CMAKE_SYSTEM_NAME}_${CMAKE_SYSTEM_PROCESSOR})
      list(APPEND curr_project_library libsasl2${LIBRARY_NAME_SUFFIX})
    endif()

    if (${dist} STREQUAL "mongodb")
      INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rd/mongo-cxx-driver-legacy-1.1.3/include)
      LINK_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rd/mongo-cxx-driver-legacy-1.1.3/lib/${CMAKE_SYSTEM_NAME}_${CMAKE_SYSTEM_PROCESSOR})
      list(APPEND curr_project_library libmongoclient${LIBRARY_NAME_SUFFIX})
    endif()

    if (${dist} STREQUAL "bufferandqueue")
      INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/2nd/BufferAndQueue/include/Buffer)
      INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/2nd/BufferAndQueue/include/Queue)                                                                                               
      INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/2nd/BufferAndQueue/include/Cache)
      LINK_DIRECTORIES(${PROJECT_SOURCE_DIR}/2nd/BufferAndQueue/lib/${CMAKE_SYSTEM_NAME}_${CMAKE_SYSTEM_PROCESSOR})
      list(APPEND curr_project_library  BufferAndQueue${LIBRARY_NAME_SUFFIX})
    endif()

    if (${dist} STREQUAL "quotepacket")
      INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/2nd/QuotePacketLib/include)
      LINK_DIRECTORIES(${PROJECT_SOURCE_DIR}/2nd/QuotePacketLib/lib/${CMAKE_SYSTEM_NAME}_${CMAKE_SYSTEM_PROCESSOR})
      list(APPEND curr_project_library libMIQuotePacket${LIBRARY_NAME_SUFFIX})
    endif()

    if (${dist} STREQUAL "quotepricefilter")
      INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/2nd/QuotePriceFilterLib/include)
      LINK_DIRECTORIES(${PROJECT_SOURCE_DIR}/2nd/QuotePriceFilterLib/lib/${CMAKE_SYSTEM_NAME}_${CMAKE_SYSTEM_PROCESSOR})
      list(APPEND curr_project_library libQuotePriceFilter${LIBRARY_NAME_SUFFIX})
    endif()

    if (${dist} STREQUAL "tabquoteapi") 
        INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rd/taptradeapi9.0/include)
        LINK_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rd/taptradeapi9.0/lib/${CMAKE_SYSTEM_NAME}_${CMAKE_SYSTEM_PROCESSOR})
        list(APPEND curr_project_library libTapQuoteAPI.so)
    endif()

    if (${dist} STREQUAL "mitradeapi") 
        INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rd/mitradeapi/include)
        LINK_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rd/mitradeapi/lib/${CMAKE_SYSTEM_NAME}_${CMAKE_SYSTEM_PROCESSOR})
        list(APPEND curr_project_library libMITradeApi.so)
    endif()

    if (${dist} STREQUAL "hst2sdk") 
        INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rd/hs_t2sdk-1.0.0.100/include)
        LINK_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rd/hs_t2sdk-1.0.0.100/lib/${CMAKE_SYSTEM_NAME}_${CMAKE_SYSTEM_PROCESSOR})
        list(APPEND curr_project_library libt2sdk.so)
    endif()

    if (${dist} STREQUAL "mimetic") 
        INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rd/mimetic-0.9.8/include)
        LINK_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rd/mimetic-0.9.8/lib/${CMAKE_SYSTEM_NAME}_${CMAKE_SYSTEM_PROCESSOR})
        list(APPEND curr_project_library mimetic${LIBRARY_NAME_SUFFIX})
    endif()

  endforeach()
  unset(curr_project_library_list PARENT_SCOPE)
  set(curr_project_library_list ${curr_project_library} PARENT_SCOPE)
endfunction()

#link target file use static library
use_library_type("static")

make_directory(${PROJECT_BINARY_DIR}/rev)
set (SVN_PATH "$ENV{SVN_PATH}")
set (SVN_REVISION $ENV{SVN_REVISION})
set (BUILD_TIME "$ENV{BUILD_TIME}")
configure_file (
  "${PROJECT_SOURCE_DIR}/service/include/rev/rev.h.in"
  "${PROJECT_BINARY_DIR}/rev/rev.h"
)
configure_file (
  "${PROJECT_SOURCE_DIR}/service/include/rev/rev.h.in"
  "${PROJECT_BINARY_DIR}/rev.h"
)
INCLUDE_DIRECTORIES(${PROJECT_BINARY_DIR})

FILE(REMOVE_RECURSE ${PROJECT_BINARY_DIR}/bin/${CMAKE_BUILD_TYPE})
FILE(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/bin/${CMAKE_BUILD_TYPE})
SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin/${CMAKE_BUILD_TYPE})
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin/${CMAKE_BUILD_TYPE})


#build current project
MESSAGE(STATUS "build current project.")

execute_process(COMMAND "pwd" OUTPUT_VARIABLE curr)
execute_process(COMMAND "dirname" ${curr} OUTPUT_VARIABLE curr_parent_path)
execute_process(COMMAND "basename" ${curr_parent_path} OUTPUT_VARIABLE parent_project)
string(REPLACE "\n" "" parent_project_path ${curr_parent_path})

if (EXISTS ${parent_project_path}/CMakeLists.txt 
    AND (NOT IS_DIRECTORY ${parent_project_path}/CMakeLists.txt)
    AND (NOT ${parent_project_path} STREQUAL ${CMAKE_SOURCE_DIR}))
  include(${parent_project_path}/CMakeLists.txt)
endif()


